home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / mkf / mkf.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-25  |  33.2 KB  |  1,276 lines

  1. /****************************************************************************
  2.  Program Name: mkf.c
  3.  Author: G.T. Sanford III                   wk (615)885-9727
  4.          7616 Nolensville Road              hm (615)776-2397
  5.          Nolensville, TN  37135
  6.  Copyright (c) February 1993
  7. -----------------------------------------------------------------------------
  8.  Description:   Fastgraph Font File Editor
  9.  
  10.                 Preliminary version. Edits existing files only.
  11.  
  12. -----------------------------------------------------------------------------
  13.  
  14.                  M O D I F I C A T I O N    H I S T O R Y 
  15.  
  16.   Date    By    Modification
  17. --------  ---  --------------------------------------------------------------
  18.  
  19.  
  20.  
  21. -------------------------- ALL RIGHTS RESERVED ------------------------------
  22. ****************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <fastgraf.h>
  28.  
  29. #define GRID_X      64
  30. #define GRID_Y      48
  31. #define MIN_X      300
  32. #define MAX_X      620
  33. #define MIN_Y       20
  34. #define MAX_Y      260
  35. #define HIDE         1
  36. #define SHOW         0
  37. #define ON           1
  38. #define OFF          0
  39. #define NUM_ARROWS   4
  40.  
  41. typedef struct
  42. {
  43.    unsigned char MAXI_X;
  44.    unsigned char MAXI_Y;
  45.    unsigned char X_SIZES[ 96 ];
  46.    unsigned char Y_SIZES[ 96 ];
  47. }  FONT_HEADER;
  48.  
  49. FONT_HEADER fhdr;
  50. unsigned char letters[ 96 ][ 384 ];      // maximum size
  51. FILE * fptr;
  52. char filename[ 65 ];
  53. int  bitmapsize;
  54. char buffer[ 81 ];
  55. int  colarray[ 65 ];
  56. int  rowarray[ 49 ];
  57. int  CURRENT_CHAR_COL = -1;
  58. int  CURRENT_CHAR_ROW = -1;
  59. int  NEW_CHAR_COL = -1;
  60. int  NEW_CHAR_ROW = -1;
  61. int  loffset = -1;
  62. int  GRID_ON = 1;
  63. int  MADE_CHANGES = 0;
  64.  
  65. int arrows[ NUM_ARROWS ][ 3 ] =
  66. {
  67.    { 294,  20, 0 },
  68.    { 294,  90, 0 },
  69.    { 300,  14, 1 },
  70.    { 340,  14, 1 }
  71. };
  72.  
  73.  
  74. /****************************************************************************
  75.     G_SETCURS
  76.    draw new cursor
  77.    Supports 640 x 350 and 640 x 480
  78. ****************************************************************************/
  79.  
  80. void g_setcurs( int x, int y )
  81. {
  82.    int oldcolor;
  83.    int ph = 14;                     // y == 350
  84.  
  85.    if ( fg_getmaxy() == 479 )       // y == 480
  86.       ph = 16;
  87.  
  88.    oldcolor = fg_getcolor();
  89.  
  90.    fg_setcolor( 15 );
  91.    fg_move( (y*8), ((x*ph)+(ph-1)) );
  92.    fg_draw( ((y*8)+7), ((x*ph)+(ph-1)) );
  93.  
  94.    if ( *(char far *)0x400017 & 0x80 )      // Insert is on
  95.    {
  96.       fg_move( (y*8), ((x*ph)+(ph-2)) );
  97.       fg_draw( ((y*8)+7), ((x*ph)+(ph-2)) );
  98.    }
  99.  
  100.    fg_setcolor( oldcolor );
  101.    return;
  102. }
  103. /*--- end of g_setcurs() --------------------------------------------------*/
  104.  
  105.  
  106.  
  107.  
  108. /****************************************************************************
  109.     G_SAYAT
  110.    Put a string in graphics video with appropriate colors
  111.    Supports 640 x 350 and 640 x 480
  112. ****************************************************************************/
  113.  
  114. void g_sayat( int row, int col, char * string, unsigned char attr )
  115. {
  116.    int len, oldcolor;
  117.    int ph = 14;                    // y == 350
  118.  
  119.    if ( fg_getmaxy() == 479 )      // y == 480
  120.       ph = 16;
  121.  
  122.    len = (int)strlen( string );
  123.    oldcolor = fg_getcolor();
  124.    fg_setcolor( (attr>>4) );
  125.    fg_rect( (col*8), (((col+len)*8)-1), (row*ph), ((row*ph)+(ph-1)) );
  126.    fg_setcolor( (attr & 0x0F) );
  127.    fg_locate( row, col );
  128.    fg_text( string, len );
  129.    fg_setcolor( oldcolor );
  130.  
  131.    return;
  132. }
  133. /*--- end of g_sayat() ----------------------------------------------------*/
  134.  
  135.  
  136.  
  137.  
  138. /****************************************************************************
  139.     TRIM
  140.    Remove trailing spaces
  141. ****************************************************************************/
  142.  
  143. char * trim( char * string )
  144. {
  145.    int length;
  146.  
  147.    length = strlen( string ) -1;
  148.    if ( string[ length ] != ' ' )           // string already trimmed
  149.       return( string );
  150.    while ( string[ length ] == ' ' && length >= 0 ) 
  151.       --length;                      // If char is ' ', decrement and retest
  152.  
  153.    string[ (length + 1) ] = '\0';    // terminate
  154.  
  155.    return( string );
  156. }
  157. /*--- end of trim() -------------------------------------------------------*/
  158.  
  159.  
  160.  
  161.  
  162. /****************************************************************************
  163.     DO_ARROW
  164.    Draw the marker arrows and lines
  165. ****************************************************************************/
  166.  
  167. void do_arrow( int i, int how )
  168. {
  169.    if ( how )
  170.       fg_setcolor( 9 );
  171.    else
  172.       fg_setcolor( 15 );
  173.  
  174.    fg_move( arrows[ i ][ 0 ], arrows[ i ][ 1 ] );
  175.    if ( arrows[ i ][ 2 ] )    // vert
  176.    {
  177.       fg_draw( arrows[ i ][ 0 ], arrows[ i ][ 1 ]+4 );
  178.       fg_point( arrows[ i ][ 0 ]-1, arrows[ i ][ 1 ]+3 );
  179.       fg_point( arrows[ i ][ 0 ]+1, arrows[ i ][ 1 ]+3 );
  180.       // vertical marker line:
  181.       if ( how )
  182.       {
  183.          if ( GRID_ON )
  184.             fg_setcolor( 7 );
  185.          else
  186.             fg_setcolor( 9 );
  187.       }
  188.       else
  189.          fg_setcolor( 12 );
  190.       fg_move( arrows[ i ][ 0 ], MIN_Y );
  191.       fg_draw( arrows[ i ][ 0 ], MAX_Y );
  192.    }
  193.    else                       // horiz
  194.    {
  195.       fg_draw( arrows[ i ][ 0 ]+4, arrows[ i ][ 1 ] );
  196.       fg_point( arrows[ i ][ 0 ]+3, arrows[ i ][ 1 ]-1 );
  197.       fg_point( arrows[ i ][ 0 ]+3, arrows[ i ][ 1 ]+1 );
  198.       // horizontal marker line:
  199.       if ( how )
  200.       {
  201.          if ( GRID_ON )
  202.             fg_setcolor( 7 );
  203.          else
  204.             fg_setcolor( 9 );
  205.       }
  206.       else
  207.          fg_setcolor( 12 );
  208.       fg_move( MIN_X, arrows[ i ][ 1 ] );
  209.       fg_draw( MAX_X, arrows[ i ][ 1 ] );
  210.    }
  211.  
  212.    return;
  213. }
  214. /*--- end of do_arrow() ---------------------------------------------------*/
  215.  
  216.  
  217.  
  218.  
  219. /****************************************************************************
  220.     MOVE_ARROW
  221.    As long as the left button is held down, we will continue to update
  222.    either the x or y coordinate of the arrow being held, within limits.
  223. ****************************************************************************/
  224.  
  225. void move_arrow( int i )
  226. {
  227.    int mx, my, buttons;
  228.    int oldmx, oldmy, j;
  229.  
  230.    while ( 1 )
  231.    {
  232.       fg_mousepos( &mx, &my, &buttons );
  233.  
  234.       if ( buttons == 0 )            // button released
  235.          break;
  236.  
  237.       if ( mx != oldmx || my != oldmy )
  238.       {
  239.          sprintf( buffer, "%3d - %3d", mx, my );
  240.          g_sayat( 0, 0, buffer, (char)0x9F );
  241.       }
  242.  
  243.       if ( arrows[ i ][ 2 ] )          // vert
  244.       {
  245.          if ( mx >= MIN_X && mx <= MAX_X )
  246.          {
  247.             if ( mx != oldmx )
  248.             {
  249.                fg_mousevis( OFF );
  250.                do_arrow( i, HIDE );
  251.                j = mx % 5;
  252.                arrows[ i ][ 0 ] = mx-j;
  253.                do_arrow( i, SHOW );
  254.                fg_mousevis( ON );
  255.             }
  256.          }
  257.       }
  258.       else                             // horiz
  259.       {
  260.          if ( my >= MIN_Y && my <= MAX_Y )
  261.          {
  262.             if ( my != oldmy )
  263.             {
  264.                fg_mousevis( OFF );
  265.                do_arrow( i, HIDE );
  266.                j = my % 5;
  267.                arrows[ i ][ 1 ] = my-j;
  268.                do_arrow( i, SHOW );
  269.                fg_mousevis( ON );
  270.             }
  271.          }
  272.       }
  273.       oldmx = mx;
  274.       oldmy = my;
  275.    }
  276.  
  277.    return;
  278. }
  279. /*--- end of move_arrow() -------------------------------------------------*/
  280.  
  281.  
  282.  
  283.  
  284. /****************************************************************************
  285.     DRAW_GRID
  286.    Put the character grid on the screen
  287. ****************************************************************************/
  288.  
  289. void draw_grid( void )
  290. {
  291.    int i, j, mx, my, dx, dy;
  292.  
  293.    fg_setcolor( 0 );
  294.    fg_rect( 200, 265, 20, 69 );           // actual size box
  295.  
  296.    fg_setcolor( 9 );
  297.    fg_rect( MIN_X, MAX_X, MIN_Y, MAX_Y );          // clear grid area
  298.  
  299.    fg_setcolor( 7 );
  300.    mx = MIN_X;
  301.    my = MIN_Y;
  302.    dy = MAX_Y;
  303.    fg_move( mx, my );
  304.    for ( i = 0; i <= GRID_X; i++ )        // draw vertical
  305.    {
  306.       colarray[ i ] = mx;                 // load array as we go
  307.       if ( GRID_ON )
  308.          fg_draw( mx, dy );
  309.       mx += 5;
  310.       fg_move( mx, my );
  311.    }
  312.  
  313.    mx = MIN_X;
  314.    my = MIN_Y;
  315.    dx = MAX_X;
  316.    fg_move( mx, my );
  317.    for ( i = 0; i <= GRID_Y; i++ )        // draw horizontal
  318.    {
  319.       rowarray[ i ] = my;                 // load array as we go
  320.       if ( GRID_ON )
  321.          fg_draw( dx, my );
  322.       my += 5;
  323.       fg_move( mx, my );
  324.    }
  325.  
  326.    fg_setcolor( 15 );
  327.  
  328.    for ( i = 0; i < NUM_ARROWS; i++ )       // little arrows in the air...
  329.    {
  330.       do_arrow( i, SHOW );
  331.    }
  332.  
  333.    return;
  334. }
  335. /*--- end of draw_grid() --------------------------------------------------*/
  336.  
  337.  
  338.  
  339.  
  340. /****************************************************************************
  341.     AT_ARROW
  342.    Is the mouse at one of the little arrows when the left button was pressed?
  343. ****************************************************************************/
  344.  
  345. int at_arrow( int mx, int my )
  346. {
  347.    int i;
  348.  
  349.    for ( i = 0; i < NUM_ARROWS; i++ )
  350.    {
  351.       if ( mx >= arrows[ i ][ 0 ]-3 && mx <= arrows[ i ][ 0 ]+3 )
  352.       {
  353.          if ( my >= arrows[ i ][ 1 ]-3 && my <= arrows[ i ][ 1 ]+3 )
  354.          {
  355.             return( i );
  356.          }
  357.       }
  358.    }
  359.  
  360.    return( -1 );
  361. }
  362. /*--- end of at_arrow() ---------------------------------------------------*/
  363.  
  364.  
  365.  
  366.  
  367. /****************************************************************************
  368.     SAVE_GRID
  369.    Install the current letter in the screen grid to the letter array
  370. ****************************************************************************/
  371.  
  372. void save_grid( void )
  373. {
  374.    int i, j, k, x, y, nb;
  375.    int row, col;
  376.    int count;
  377.  
  378.    if ( loffset < 0 )
  379.       return;
  380.  
  381.    col = 0;
  382.    x = (int)fhdr.X_SIZES[ loffset ];
  383.    y = (int)fhdr.Y_SIZES[ loffset ];
  384.  
  385.    // actual number of bytes for this letter
  386.    if ( x >  0 && x <  8 )
  387.       nb = 1;
  388.    if ( x >=  8 && x < 16 )
  389.       nb = 2;
  390.    if ( x >= 16 && x < 24 )
  391.       nb = 3;
  392.    if ( x >= 24 && x < 32 )
  393.       nb = 4;
  394.    if ( x >= 32 && x < 40 )
  395.       nb = 5;
  396.    if ( x >= 40 && x < 48 )
  397.       nb = 6;
  398.    if ( x >= 48 && x < 56 )
  399.       nb = 7;
  400.    if ( x >= 56 && x < 64 )
  401.       nb = 8;
  402.  
  403.    for ( row = 0; row < y;  )
  404.    {
  405.       for ( j = 0; j < nb; j++ )
  406.       {
  407.          count = 128;
  408.          for ( k = 0; k < 8; k++ )
  409.          {
  410.             if ( fg_getpixel( colarray[ col ]+1, rowarray[ row ]+1 ) == 15 )
  411.             {
  412.                letters[ loffset ][ ((row*nb)+j) ] |= count;  // turn on bit
  413.             }
  414.             else
  415.             {
  416.                letters[ loffset ][ ((row*nb)+j) ] &= ~count;  // turn off bit
  417.             }
  418.             count /= 2;
  419.             col++;
  420.          }
  421.       }
  422.       row++;
  423.       col = 0;
  424.       if ( row > y )
  425.          break;
  426.    }
  427.  
  428.    return;
  429. }
  430. /*--- end of save_grid() --------------------------------------------------*/
  431.  
  432.  
  433.  
  434.  
  435. /****************************************************************************
  436.     LOAD_GRID
  437.    Install the current letter into the screen grid
  438. ****************************************************************************/
  439.  
  440. void load_grid( void )
  441. {
  442.    int i, j, k, x, y, nb;
  443.    int row, col;
  444.    int count;
  445.  
  446.    col = 0;
  447.    x = (int)fhdr.X_SIZES[ loffset ];
  448.    y = (int)fhdr.Y_SIZES[ loffset ];
  449.  
  450.    sprintf( buffer, "%2d x %2d", x, y );
  451.    g_sayat( 5, 26, buffer, 0x1F );
  452.  
  453.    // actual number of bytes for this letter
  454.    if ( x >  0 && x <  8 )
  455.       nb = 1;
  456.    if ( x >=  8 && x < 16 )
  457.       nb = 2;
  458.    if ( x >= 16 && x < 24 )
  459.       nb = 3;
  460.    if ( x >= 24 && x < 32 )
  461.       nb = 4;
  462.    if ( x >= 32 && x < 40 )
  463.       nb = 5;
  464.    if ( x >= 40 && x < 48 )
  465.       nb = 6;
  466.    if ( x >= 48 && x < 56 )
  467.       nb = 7;
  468.    if ( x >= 56 && x < 64 )
  469.       nb = 8;
  470.  
  471.    fg_mousevis( OFF );
  472.    for ( i = 0; i < (fhdr.MAXI_X*8); i++ )       // clear current letter
  473.    {
  474.       for ( j = 0; j < fhdr.MAXI_Y; j++ )
  475.       {
  476.          fg_setcolor( 9 );
  477.          if ( GRID_ON )
  478.             fg_rect( colarray[ i ]+1, colarray[ i ]+4, rowarray[ j ]+1, rowarray[ j ]+4 );
  479.          else
  480.             fg_rect( colarray[ i ], colarray[ i ]+4, rowarray[ j ], rowarray[ j ]+4 );
  481.          fg_setcolor( 0 );
  482.          fg_point( 201+i, 21+j );
  483.       }
  484.    }
  485.  
  486.    for ( row = 0; row < y; row++ )
  487.    {
  488.       for ( j = 0; j < nb; j++ )
  489.       {
  490.          count = 128;
  491.          for ( k = 0; k < 8; k++ )
  492.          {
  493.             if ( letters[ loffset ][ ((row*nb)+j) ] & count )
  494.             {
  495.                fg_setcolor( 15 );
  496.                if ( GRID_ON )
  497.                   fg_rect( colarray[ col ]+1, colarray[ col ]+4, rowarray[ row ]+1, rowarray[ row ]+4 );
  498.                else
  499.                   fg_rect( colarray[ col ], colarray[ col ]+4, rowarray[ row ], rowarray[ row ]+4 );
  500.                fg_point( 201+col, 21+row );
  501.             }
  502.             count /= 2;
  503.             col++;
  504.          }
  505.       }
  506.       col = 0;
  507.    }
  508.  
  509.    // adjust arrows and marker lines to reflect the new letter:
  510.    do_arrow( 1, HIDE );
  511.    do_arrow( 3, HIDE );
  512.    arrows[ 1 ][ 1 ] = ( fhdr.Y_SIZES[ loffset ] * 5 ) + MIN_Y;
  513.    arrows[ 3 ][ 0 ] = ( fhdr.X_SIZES[ loffset ] * 5 ) + MIN_X;
  514.    do_arrow( 1, SHOW );
  515.    do_arrow( 3, SHOW );
  516.  
  517.    fg_mousevis( ON );
  518.  
  519.    return;
  520. }
  521. /*--- end of load_grid() --------------------------------------------------*/
  522.  
  523.  
  524.  
  525.  
  526. /****************************************************************************
  527.     FIND_COLUMN
  528.    Locate the column of the new letter display request
  529. ****************************************************************************/
  530.  
  531. int find_column( int mx )
  532. {
  533.    int col, st, i;
  534.  
  535.    col = 0;
  536.    for ( st = 75, i = 0; st <= 587 ; st += 16, i++ )
  537.    {
  538.       if ( mx >= st && mx < st+16 )
  539.       {
  540.          col = st+1;
  541.          NEW_CHAR_COL = i;
  542.          break;
  543.       }
  544.    }
  545.  
  546.    return( col );
  547. }
  548. /*--- end of find_column() ------------------------------------------------*/
  549.  
  550.  
  551.  
  552.  
  553. /****************************************************************************
  554.     ERASE_CURRENT
  555.    Un-hilite the currently hi-lited letter
  556. ****************************************************************************/
  557.  
  558. void erase_current( void )
  559. {
  560.    int i, x, y;
  561.  
  562.    if ( CURRENT_CHAR_COL == -1 )
  563.       return;
  564.  
  565.    x = 76 + ( CURRENT_CHAR_COL * 16 );
  566.  
  567.    switch ( CURRENT_CHAR_ROW )
  568.    {
  569.       case 0:
  570.          y = 316;
  571.          break;
  572.       case 1:
  573.          y = 344;
  574.          break;
  575.       case 2:
  576.          y = 376;
  577.          break;
  578.    }
  579.  
  580.    fg_setcolor( 9 );
  581.    fg_paint( x, y );
  582.    fg_setcolor( 15 );
  583.  
  584.    return;
  585. }
  586. /*--- end of erase_current() ----------------------------------------------*/
  587.  
  588.  
  589.  
  590.  
  591. /****************************************************************************
  592.     SET_NEW
  593.    Hilite the newly requested letter
  594. ****************************************************************************/
  595.  
  596. int set_new( int x, int row )
  597. {
  598.    int y;
  599.    char ch[ 2 ];
  600.  
  601.    if ( loffset >= 0 )
  602.       save_grid();
  603.  
  604.    switch ( row )
  605.    {
  606.       case 0:
  607.          y = 316;
  608.          NEW_CHAR_ROW = 0;
  609.          ch[ 0 ] = (char)( NEW_CHAR_COL+32 );
  610.          loffset = NEW_CHAR_COL;
  611.          break;
  612.       case 1:
  613.          y = 344;
  614.          NEW_CHAR_ROW = 1;
  615.          ch[ 0 ] = (char)( NEW_CHAR_COL+64 );
  616.          loffset = ( NEW_CHAR_COL+32 );
  617.          break;
  618.       case 2:
  619.          y = 376;
  620.          NEW_CHAR_ROW = 2;
  621.          ch[ 0 ] = (char)( NEW_CHAR_COL+96 );
  622.          loffset = ( NEW_CHAR_COL+64 );
  623.          break;
  624.    }
  625.  
  626.    if ( loffset < 0 )
  627.       loffset = 0;
  628.  
  629.    CURRENT_CHAR_COL = NEW_CHAR_COL;
  630.    CURRENT_CHAR_ROW = NEW_CHAR_ROW;
  631.  
  632.    fg_setcolor( 12 );
  633.    fg_paint( x, y );
  634.  
  635.    ch[ 1 ] = '\0';
  636.    g_sayat( 2, 22, ch, (char)0x0F );
  637.    fg_setcolor( 15 );
  638.  
  639.    load_grid();
  640.  
  641.    return( 0 );
  642. }
  643. /*--- end of set_new() ----------------------------------------------------*/
  644.  
  645.  
  646.  
  647.  
  648. /****************************************************************************
  649.     G_GETKEY
  650.    Get a key from the keyboard
  651. ****************************************************************************/
  652.  
  653. int g_getkey( void )
  654. {
  655.    unsigned char key;
  656.    unsigned char aux;
  657.  
  658.    fg_getkey( &key, &aux );
  659.  
  660.    if ( aux == 0 )
  661.       return( (int)key );
  662.    else
  663.       return( (int)(aux+256) );          // all extended keys will be > 256
  664. }
  665. /*--- end of g_getkey() ---------------------------------------------------*/
  666.  
  667.  
  668.  
  669.  
  670. /****************************************************************************
  671.     G_SMGETS
  672.    Input the font file name
  673.    ( This is a greatly simplified version of natgets() )
  674. ****************************************************************************/
  675.  
  676. int g_smgets( int row, int scol, char * string, char * mask, int * chg, int pct )
  677. {
  678.    int i, col, slen;
  679.    int ch;
  680.    char disp_buff[ 81 ];
  681.  
  682.    col = scol;
  683.    slen = (signed int)strlen( mask );
  684.    i = (signed int)strlen( string );
  685.    while ( i < slen )
  686.       string[ i++ ] = ' ';
  687.    memcpy( disp_buff, string, slen );
  688.    disp_buff[ slen ] = 0;
  689.    string[ slen ] = 0;
  690.    i = 0;
  691.  
  692.    while ( 1 )
  693.    {
  694.       g_sayat( row, scol, disp_buff, 0x4E );
  695.       g_setcurs( row, col );
  696.       ch = toupper( g_getkey() );
  697.       switch ( ch )
  698.       {
  699.          case 27:                           // ESCape
  700.          case 13:                           // Enter
  701.             goto finished;
  702.          case 8:                            // backspace
  703.             if ( col > scol )
  704.             {
  705.                col--;
  706.                string[ --i ] = ' ';
  707.                disp_buff[ i ] = ' ';
  708.             }
  709.             break;
  710.          case 333:                          // right arrow
  711.             if ( col < ((scol+slen)-1) )
  712.             {
  713.                col++;
  714.                i++;
  715.             }
  716.             break;
  717.          case 331:                          // left arrow
  718.             if ( col > scol )
  719.             {
  720.                col--;
  721.                i--;
  722.             }
  723.             break;
  724.          default:
  725.             if ( i < slen )
  726.             {
  727.                if ( isprint( ch ) )
  728.                {
  729.                   disp_buff[ i ] = ch;
  730.                   string[ i++ ] = ch;
  731.                   col++;
  732.                }
  733.             }
  734.             break;
  735.       }
  736.    }
  737.  
  738.    finished:
  739.  
  740.    return( ch );
  741. }
  742. /*--- end of g_smgets() ---------------------------------------------------*/
  743.  
  744.  
  745.  
  746.  
  747. /****************************************************************************
  748.     LOAD_FONT
  749.    Load the requested font file
  750. ****************************************************************************/
  751.  
  752. void load_font( void )
  753. {
  754.    int result, i;
  755.    char * chp;
  756.  
  757.    erase_current();
  758.  
  759.    g_sayat( 17,  1, "Current Font: ", 0x17 );
  760.    while ( 1 )
  761.    {
  762.       result = g_smgets( 17, 15, filename, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", &i, 0 );
  763.  
  764.       trim( filename );
  765.       chp = strchr( filename, '.' );
  766.       if ( chp != NULL )                   // found '.'
  767.          memset( chp, '\0', 4 );
  768.       strcat( filename, ".FGF" );
  769.       g_sayat( 17, 15, "                                        ", 0x99 );
  770.       g_sayat( 17, 15, filename, 0x0A );
  771.  
  772.       fptr = fopen( filename, "rb" );
  773.       if ( fptr == NULL )
  774.       {
  775.          sprintf( buffer, "Cannot find %s", filename );
  776.          g_sayat( 27, 10, buffer, 0x4F );
  777.          fg_waitfor( 48 );
  778.          fg_setcolor( 9 );
  779.          fg_rect( 80, 640, 432, 448 );        // clear error message
  780.          fg_setcolor( 15 );
  781.       }
  782.       else
  783.          break;
  784.    }
  785.  
  786.    fread( &fhdr, sizeof( char ), sizeof( fhdr ), fptr );
  787.  
  788.    // adjust arrows and marker lines to reflect this new font:
  789.    do_arrow( 1, HIDE );
  790.    do_arrow( 3, HIDE );
  791.    arrows[ 1 ][ 1 ] = ( fhdr.MAXI_Y * 5 ) + MIN_Y;
  792.    arrows[ 3 ][ 0 ] = ( (fhdr.MAXI_X * 8) * 5 ) + MIN_X;
  793.    do_arrow( 1, SHOW );
  794.    do_arrow( 3, SHOW );
  795.    
  796.    bitmapsize = (int)((int)fhdr.MAXI_X * (int)fhdr.MAXI_Y);
  797.  
  798.    for ( i = 0; i < 96; i++ )       // load each character
  799.       fread( &letters[ i ], sizeof( char ), bitmapsize, fptr );
  800.  
  801.    fclose( fptr );
  802.  
  803.    loffset = -1;
  804.    CURRENT_CHAR_COL = -1;
  805.    CURRENT_CHAR_ROW = -1;
  806.    NEW_CHAR_COL = -1;
  807.    NEW_CHAR_ROW = -1;
  808.    MADE_CHANGES = 0;
  809.  
  810.    return;
  811. }
  812. /*--- end of load_font() --------------------------------------------------*/
  813.  
  814.  
  815.  
  816.  
  817. /****************************************************************************
  818.     SAVE_FONT
  819.    Save the modified font file
  820. ****************************************************************************/
  821.  
  822. void save_font( void )
  823. {
  824.    int i, ok = 0;
  825.    int mx, my, buttons;
  826.    int result;
  827.    char * chp;
  828.  
  829.    if ( filename[ 0 ] == ' ' || filename[ 0 ] == '\0' )
  830.    {
  831.       g_sayat( 17,  1, "Current Font: ", 0x17 );
  832.       result = g_smgets( 17, 15, filename, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", &i, 0 );
  833.       trim( filename );
  834.       chp = strchr( filename, '.' );
  835.       if ( chp != NULL )
  836.          memset( chp, '\0', 4 );
  837.       strcat( filename, ".FGF" );
  838.       g_sayat( 17, 15, "                                        ", 0x99 );
  839.       g_sayat( 17, 15, filename, 0x9F );
  840.    }
  841.  
  842.    if ( access( filename, 0 ) == 0 )      // file exists
  843.    {
  844.       sprintf( buffer, " %s Already Exists, Overwrite? ", trim( filename ) );
  845.       g_sayat( 27, 10, buffer, 0x4F );
  846.  
  847.       fg_setcolor( 1 );
  848.       fg_rect( 140, 220, 104, 136 );
  849.       fg_rect( 140, 220, 140, 172 );
  850.       fg_setcolor( 7 );
  851.       fg_box( 140, 220, 104, 136 );
  852.       fg_box( 140, 220, 140, 172 );
  853.       g_sayat( 7, 18, "Overwrite", 0x1F );
  854.       g_sayat( 9, 18, " Cancel", 0x1F );
  855.  
  856.       fg_sound( 800, 6 );
  857.       fg_sound( 400, 6 );
  858.       fg_mousemov( 180, 156 );
  859.       fg_mousevis( ON );
  860.  
  861.       while ( 1 )
  862.       {
  863.          fg_mousepos( &mx, &my, &buttons );
  864.          if ( buttons == 0x01 )        // left button
  865.          {
  866.             if ( mx >= 140 && mx <= 220 )
  867.             {
  868.                if ( my >= 104 && my <= 136 )     // overwrite
  869.                {
  870.                   ok = 1;
  871.                   break;
  872.                }
  873.                if ( my >= 140 && my <= 172 )     // cancel
  874.                {
  875.                   ok = 0;
  876.                   break;
  877.                }
  878.             }
  879.          }
  880.       }
  881.    }
  882.  
  883.    fg_mousevis( OFF );
  884.    fg_setcolor( 9 );
  885.    fg_rect( 80, 640, 432, 448 );        // clear error message
  886.    fg_rect( 140, 220, 104, 136 );       // clear overwrite
  887.    fg_rect( 140, 220, 140, 172 );       // clear cancel
  888.    fg_mousevis( ON );
  889.  
  890.    if ( ok )
  891.    {
  892.       fptr = fopen( filename, "wb" );
  893.       fwrite( &fhdr, sizeof( char ), sizeof( fhdr ), fptr );
  894.       for ( i = 0; i < 96; i++ )       // load each character
  895.       {
  896.          fwrite( &letters[ i ], sizeof( char ), bitmapsize, fptr );
  897.       }
  898.       fclose( fptr );
  899.    }
  900.  
  901.    return;
  902. }
  903. /*--- end of save_font() --------------------------------------------------*/
  904.  
  905.  
  906.  
  907.  
  908. /****************************************************************************
  909.     PROCESS_FILL
  910.    Left mouse button was pressed, find out what they want processed and do it.
  911. ****************************************************************************/
  912.  
  913. void process_fill( int mx, int my )
  914. {
  915.    int i, j, foundx = 0, foundy = 0;
  916.    int lpx, lpy, ok, buttons;
  917.  
  918.    for ( i = 0; i < GRID_X; i++ )
  919.    {
  920.       if ( mx >= colarray[ i ] && mx < colarray[ i+1 ] )
  921.       {
  922.          foundx = 1;          // inside screen grid x coordinates
  923.          break;
  924.       }
  925.    }
  926.  
  927.    if ( foundx )
  928.    {
  929.       for ( j = 0; j < GRID_Y; j++ )
  930.       {
  931.          if ( my >= rowarray[ j ] && my < rowarray[ j+1 ] )
  932.          {
  933.             foundy = 1;          // inside screen grid y coordinates
  934.             break;
  935.          }
  936.       }
  937.    }
  938.    if ( foundx && foundy )       // want to hi-lite a grid block
  939.    {
  940.       fg_setcolor( 15 );
  941.       fg_mousevis( OFF );
  942.       if ( GRID_ON )
  943.          fg_rect( colarray[ i ]+1, colarray[ i ]+4, rowarray[ j ]+1, rowarray[ j ]+4 );
  944.       else
  945.          fg_rect( colarray[ i ], colarray[ i ]+4, rowarray[ j ], rowarray[ j ]+4 );
  946.       lpx = 201+i;
  947.       lpy = 21+j;
  948.       fg_point( lpx, lpy );
  949.       fg_mousevis( ON );
  950.       MADE_CHANGES = 1;
  951.    }
  952.    else                                   // outside screen grid coordinates
  953.    {
  954.       if ( my >= 315 && my <= 405 )             // character grid
  955.       {
  956.          if ( my >= 315 && my < 343 )           // 1st row
  957.          {
  958.             lpx = find_column( mx );
  959.             if ( lpx )
  960.             {
  961.                fg_mousevis( OFF );
  962.                erase_current();
  963.                set_new( lpx, 0 );
  964.                fg_waitfor( 2 );
  965.                fg_mousevis( ON );
  966.             }
  967.          }
  968.          else if ( my >= 343 && my < 375 )      // 2nd row
  969.          {
  970.             lpx = find_column( mx );
  971.             if ( lpx )
  972.             {
  973.                fg_mousevis( OFF );
  974.                erase_current();
  975.                set_new( lpx, 1 );
  976.                fg_waitfor( 2 );
  977.                fg_mousevis( ON );
  978.             }
  979.          }
  980.          else if ( my >= 375 && my <= 405 )     // 3rd row
  981.          {
  982.             lpx = find_column( mx );
  983.             if ( lpx )
  984.             {
  985.                fg_mousevis( OFF );
  986.                erase_current();
  987.                set_new( lpx, 2 );
  988.                fg_waitfor( 2 );
  989.                fg_mousevis( ON );
  990.             }
  991.          }
  992.       }
  993.       else if ( ( j = at_arrow( mx, my ) ) != -1 )    // maybe moving arrows
  994.       {
  995.          move_arrow( j );
  996.       }
  997.       else if ( my >= 40 && my <= 232 )            // main menu choices
  998.       {
  999.          if ( mx >= 6 && mx <= 99 )
  1000.          {
  1001.             if ( my >= 40 && my <= 71 )            // clear grid
  1002.             {
  1003.                fg_mousevis( OFF );
  1004.                fg_setcolor( 12 );
  1005.                fg_paint( 7, 41 );
  1006.                draw_grid();
  1007.                load_grid();
  1008.                fg_waitfor( 2 );
  1009.                fg_mousevis( OFF );
  1010.                fg_setcolor( 1 );
  1011.                fg_paint( 7, 41 );
  1012.                fg_mousevis( ON );
  1013.             }
  1014.             else if ( my >= 72 && my <= 103 )     // load font
  1015.             {
  1016.                fg_mousevis( OFF );
  1017.                fg_setcolor( 12 );
  1018.                fg_paint( 7, 73 );
  1019.                draw_grid();
  1020.                load_font();
  1021.                fg_waitfor( 2 );
  1022.                fg_setcolor( 1 );
  1023.                fg_paint( 7, 73 );
  1024.                fg_mousevis( ON );
  1025.             }
  1026.             else if ( my >= 104 && my <= 135 )      // save font
  1027.             {
  1028.                fg_mousevis( OFF );
  1029.                fg_setcolor( 12 );
  1030.                fg_paint( 7, 105 );
  1031.                save_font();
  1032.                fg_waitfor( 2 );
  1033.                fg_setcolor( 1 );
  1034.                fg_paint( 7, 105 );
  1035.                fg_mousevis( ON );
  1036.             }
  1037.             else if ( my >= 136 && my <= 167 )      // grid on/off
  1038.             {
  1039.                fg_mousevis( OFF );
  1040.                if ( GRID_ON )
  1041.                {
  1042.                   GRID_ON = 0;
  1043.                   g_sayat(  9, 6, "ON", 0x1F );
  1044.                   g_sayat(  9, 9, "OFF", 0x1C );
  1045.                }
  1046.                else
  1047.                {
  1048.                   GRID_ON = 1;
  1049.                   g_sayat(  9, 6, "ON", 0x1C );
  1050.                   g_sayat(  9, 9, "OFF", 0x1F );
  1051.                }
  1052.                draw_grid();
  1053.                load_grid();
  1054.                fg_waitfor( 4 );
  1055.                fg_setcolor( 1 );
  1056.                fg_mousevis( ON );
  1057.             }
  1058.             else if ( my >= 168 && my <= 199 )       // Exit
  1059.             {
  1060.                ok = 1;
  1061.                if ( MADE_CHANGES )
  1062.                {
  1063.                   sprintf( buffer, " Changes have been made. Quit anyway? " );
  1064.                   g_sayat( 27, 10, buffer, 0x4F );
  1065.  
  1066.                   fg_setcolor( 1 );
  1067.                   fg_rect( 140, 240, 104, 136 );
  1068.                   fg_rect( 140, 240, 140, 172 );
  1069.                   fg_setcolor( 7 );
  1070.                   fg_box( 140, 240, 104, 136 );
  1071.                   fg_box( 140, 240, 140, 172 );
  1072.                   g_sayat( 7, 18, "Exit To DOS", 0x1F );
  1073.                   g_sayat( 9, 19, "Continue", 0x1F );
  1074.  
  1075.                   fg_sound( 800, 6 );
  1076.                   fg_sound( 400, 6 );
  1077.                   fg_mousemov( 180, 156 );
  1078.                   fg_mousevis( ON );
  1079.  
  1080.                   while ( 1 )
  1081.                   {
  1082.                      fg_mousepos( &mx, &my, &buttons );
  1083.                      if ( buttons == 0x01 )                  // left button
  1084.                      {
  1085.                         if ( mx >= 140 && mx <= 220 )
  1086.                         {
  1087.                            if ( my >= 104 && my <= 136 )     // quit to DOS
  1088.                            {
  1089.                               ok = 1;
  1090.                               break;
  1091.                            }
  1092.                            if ( my >= 140 && my <= 172 )     // continue
  1093.                            {
  1094.                               ok = 0;
  1095.                               break;
  1096.                            }
  1097.                         }
  1098.                      }
  1099.                   }
  1100.                   fg_mousevis( OFF );
  1101.                   fg_setcolor( 9 );
  1102.                   fg_rect( 80, 640, 432, 448 );        // clear error message
  1103.                   fg_rect( 140, 240, 104, 136 );       // clear quit to DOS
  1104.                   fg_rect( 140, 240, 140, 172 );       // clear continue
  1105.                   fg_mousevis( ON );
  1106.                }
  1107.                if ( ok )
  1108.                {
  1109.                   fg_setmode( 3 );
  1110.                   exit( 0 );
  1111.                }
  1112.             }
  1113.          }
  1114.       }
  1115.    }
  1116.  
  1117.    return;
  1118. }
  1119. /*--- end of process_fill() -----------------------------------------------*/
  1120.  
  1121.  
  1122.  
  1123.  
  1124. /****************************************************************************
  1125.     PROCESS_EMPTY
  1126.    Right mouse button was pressed, they want to clear a grid block.
  1127. ****************************************************************************/
  1128.  
  1129. void process_empty( int mx, int my )
  1130. {
  1131.    int i, j, foundx = 0, foundy = 0;
  1132.    int lpx, lpy;
  1133.  
  1134.    for ( i = 0; i < GRID_X; i++ )
  1135.    {
  1136.       if ( mx >= colarray[ i ] && mx < colarray[ i+1 ] )
  1137.       {
  1138.          foundx = 1;
  1139.          break;
  1140.       }
  1141.    }
  1142.  
  1143.    if ( foundx )
  1144.    {
  1145.       for ( j = 0; j < GRID_Y; j++ )
  1146.       {
  1147.          if ( my >= rowarray[ j ] && my < rowarray[ j+1 ] )
  1148.          {
  1149.             foundy = 1;
  1150.             break;
  1151.          }
  1152.       }
  1153.    }
  1154.    if ( foundx && foundy )
  1155.    {
  1156.       fg_setcolor( 9 );
  1157.       fg_mousevis( OFF );
  1158.       if ( GRID_ON )
  1159.          fg_rect( colarray[ i ]+1, colarray[ i ]+4, rowarray[ j ]+1, rowarray[ j ]+4 );
  1160.       else
  1161.          fg_rect( colarray[ i ], colarray[ i ]+4, rowarray[ j ], rowarray[ j ]+4 );
  1162.       lpx = 201+i;
  1163.       lpy = 21+j;
  1164.       fg_setcolor( 0 );
  1165.       fg_point( lpx, lpy );
  1166.       fg_mousevis( ON );
  1167.       MADE_CHANGES = 1;
  1168.    }
  1169.  
  1170.    return;
  1171. }
  1172. /*--- end of process_empty() ----------------------------------------------*/
  1173.  
  1174.  
  1175.  
  1176.  
  1177. /****************************************************************************
  1178.     MAIN
  1179.    Set up the mode, draw the initial screen, process mouse movement.
  1180. ****************************************************************************/
  1181.  
  1182. void main( int argc, char ** argv )
  1183. {
  1184.    int mx, my, buttons = 0;
  1185.    int oldmx, oldmy, i;
  1186.  
  1187.    fg_setmode( fg_bestmode( 640, 480, 1 ) );
  1188.    fg_setcolor( 9 );
  1189.    fg_rect( 0, 639, 0, 479 );       // clear screen
  1190.  
  1191.    draw_grid();
  1192.  
  1193.    if ( fg_mouseini() == -1 )
  1194.    {
  1195.       fg_setmode( 3 );
  1196.       printf( "Mouse Required\n" );
  1197.       exit( 0 );
  1198.    }
  1199.    fg_mousevis( ON );
  1200.  
  1201.    fg_setcolor( 1 );
  1202.    fg_rect( 6, 99, 40, 232 );
  1203.    fg_setcolor( 7 );
  1204.    fg_move( 6, 40 );
  1205.    fg_draw( 99, 40 );
  1206.    fg_move( 6, 72 );
  1207.    fg_draw( 99, 72 );
  1208.    fg_move( 6, 104 );
  1209.    fg_draw( 99, 104 );
  1210.    fg_move( 6, 136 );
  1211.    fg_draw( 99, 136 );
  1212.    fg_move( 6, 168 );
  1213.    fg_draw( 99, 168 );
  1214.    fg_move( 6, 200 );
  1215.    fg_draw( 99, 200 );
  1216.    fg_move( 6, 232 );
  1217.    fg_draw( 99, 232 );
  1218.    fg_move( 6, 40 );
  1219.    fg_draw( 6, 232 );
  1220.    fg_move( 99, 40 );
  1221.    fg_draw( 99, 232 );
  1222.  
  1223.    g_sayat(  3, 1, "CLEAR GRID", 0x1F );
  1224.    g_sayat(  5, 1, "LOAD FONT", 0x1F );
  1225.    g_sayat(  7, 1, "SAVE FONT", 0x1F );
  1226.    g_sayat(  9, 1, "GRID ON/OFF", 0x1F );
  1227.    g_sayat( 11, 1, "EXIT", 0x1F );
  1228.    g_sayat(  9, 6, "ON", 0x1C );
  1229.  
  1230.    g_sayat( 20, 10, "  ! \" # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?", (char)0x9F );
  1231.    g_sayat( 22, 10, "@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \\ ] ^ _", (char)0x9F );
  1232.    g_sayat( 24, 10, "` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~",    (char)0x9F );
  1233.  
  1234.    fg_setcolor( 7 );
  1235.    fg_move( 75, 315 );
  1236.    fg_draw( 587, 315 );
  1237.    fg_move( 75, 343 );
  1238.    fg_draw( 587, 343 );
  1239.    fg_move( 75, 375 );
  1240.    fg_draw( 587, 375 );
  1241.    fg_move( 75, 405 );
  1242.    fg_draw( 587, 405 );
  1243.  
  1244.    for ( i = 75; i < 588; i += 16 )
  1245.    {
  1246.       fg_move( i, 315 );
  1247.       fg_draw( i, 405 );
  1248.    }
  1249.  
  1250.    fg_mousemov( 86, 86 );        // ready to load font
  1251.  
  1252.    while ( 1 )
  1253.    {
  1254.       fg_mousepos( &mx, &my, &buttons );
  1255.       if ( mx != oldmx || my != oldmy )
  1256.       {
  1257.          sprintf( buffer, "%3d - %3d", mx, my );
  1258.          g_sayat( 0, 0, buffer, (char)0x9F );
  1259.          oldmx = mx;
  1260.          oldmy = my;
  1261.       }
  1262.       if ( buttons == 0x01 )        // left button
  1263.       {
  1264.          process_fill( mx, my );
  1265.       }
  1266.       if ( buttons == 0x02 )        // right button
  1267.       {
  1268.          process_empty( mx, my );
  1269.       }
  1270.    }
  1271. }
  1272. /*--- end of main() -------------------------------------------------------*/
  1273.  
  1274. /*--- end of file ---------------------------------------------------------*/
  1275.  
  1276.